package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class StrategyDetail extends BaseDomain {
    public static final int STATE_NORMAL = 0; // 正常
    public static final int STATE_RELEASE = 1; //发布


    private String title; // 标题

    private Date createTime; // 创建时间

    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date releaseTime; // 发布时间

    private Integer sequence; // 序号

    private StrategyCatalog catalog; // 攻略类别

    private String coverUrl; // 背景图片

    private Integer state=STATE_NORMAL; // 状态

    // 关联攻略内容
    private StrategyContent content;

    //页面数据 回显
    public String getJsonString(){
        Map<String,Object> map  = new HashMap<>();
        map.put("id",getId());
        if(catalog != null){
            map.put("catalogId",catalog.getId());
            map.put("catalogName",catalog.getName());
            map.put("strategyId",catalog.getStrategy().getId());
        }
        map.put("title",title);
        map.put("releaseTime", DateUtil.date2string(releaseTime,"yyyy-MM-dd"));
        map.put("coverUrl",coverUrl);
        map.put("sequence",sequence);
        map.put("state",state);
        return JSONUtil.toJSONString(map);
    }

    public String getStateDisplay(){
        // 防止NPE
        if(state == null){
            return "";
        }
        if(state == STATE_NORMAL){
            return "正常";
        }else if(state == STATE_RELEASE) {
            return "发布";
        }
        return "";
    }

}